package com.kha.listone.common;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;

import com.kha.listone.ListOne;
import com.kha.listone.util.Commands;
import com.kha.listone.util.Globals;
import com.kha.listone.util.Orientation;
import com.kha.listone.util.operation.OperationsQueue;
import com.nokia.mid.ui.CategoryBar;

public class CompoundScreen extends List implements CommandListener {

	public static final short TASK_ID = 0;
	public static final short LIST_ID = 1;
	public static final short FILTER_ID = 2;

	protected final ListOne mainMIDlet;
	protected OperationsQueue enqueueOperation;

	private CategoryBar tabBar;

	public CompoundScreen(ListOne midlet, String title, int type) {
		super(title, type);
		this.mainMIDlet = midlet;
		enqueueOperation = new OperationsQueue();

		initScreen();
	}

	protected void initScreen() {

		Orientation.enableOrientations();

		// Option Menu Commands
		if (Globals.HAVE_DROPBOX) {
			this.addCommand(Commands.SYNC);
		}
		this.addCommand(Commands.SETTING);
		this.addCommand(Commands.ABOUT);

		// Option Menu Commands
		this.setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		if (c == Commands.ABOUT) {
			mainMIDlet.next(mainMIDlet.getAboutScreen());
		}

		if (c == Commands.SETTING) {
			mainMIDlet.next(mainMIDlet.getSettingScreen());
		}

		if (c == Commands.SYNC) {
			// TODO
		}
	}

	public CategoryBar getTabBar() {
		return tabBar;
	}

	public void setTabBar(CategoryBar tabBar) {
		this.tabBar = tabBar;
	}

	public void refresh() {
		// Option Menu Commands
		
		this.removeCommand(Commands.SYNC);
		
		if (Globals.HAVE_DROPBOX) {
			this.addCommand(Commands.SYNC);
		}
	}
	
	protected void showMessage(String title, String text, AlertType type, Image image){
		Alert alert = new Alert(title, text, image, type);
		mainMIDlet.showDisplay(alert);
	}
}
